﻿using UnityEngine;
using System.Collections;

public static class TornRealExtensions
{
    public static bool Alive(this MonoBehaviour mb)
    {
        return mb.GetComponent<Destructible>().life > 0;
    }

    public static void Attack(this MonoBehaviour mb, float damage)
    {
        mb.GetComponent<Destructible>().Attack(damage);
    }

    public static bool CanMove(this MonoBehaviour mb, bool? set = null)
    {
        if (set != null)
            mb.GetComponent<BaseUnit>().canMove = set.Value;
        return mb.GetComponent<BaseUnit>().canMove;
    }

    public static Destructible Target(this MonoBehaviour mb)
    {
        return mb.GetComponent<BaseUnit>().target;
    }

    public static void PlayAnim(this MonoBehaviour mb, string name)
    {
        mb.GetComponent<UnitAnimations>().Play(name);
    }

    public static void PlayAnim(this MonoBehaviour mb, string name, bool front)
    {
        mb.GetComponent<UnitAnimations>().Play(name, front);
    }

    public static UnitAnimations Anims(this MonoBehaviour mb)
    {
        return mb.GetComponent<UnitAnimations>();
    }


    public static BaseUnit Unit(this MonoBehaviour mb)
    {
        return mb.GetComponent<BaseUnit>();
    }
}
